<script setup lang="ts">
import { useUser } from "@/stores/user";
const { getUser } = useUser();
const userInfo = getUser();

const options = [
  {
    value: 1,
    label: "首页",
  },
  {
    value: 2,
    label: "用户中心",
  },
];

const handleOption = (e) => {
  console.log("--e--", e.target.innerHTML);
}

</script>

<template>
  <header class="sticky py-5 flex items-center backdrop-blur-xs">
    <img
      alt="Vue logo"
      class="logo"
      src="@/assets/logo.svg"
      width="30"
      height="30"
    />

    <nav>
      <router-link to="/">看板</router-link>
      <router-link to="/about">工具</router-link>
      <router-link to="/user">用户</router-link>
      <router-link to="/chinamap">地图</router-link>
    </nav>

    <el-popover placement="bottom-end" width="200" trigger="hover">
      <ul @click="handleOption">
        <li
          class="pointer-events-auto py-2 px-5 border-b border-solid border-gray-400"
          v-for="option in options"
          :key="option.value"
        >
          {{ option.label }}
        </li>
      </ul>
      <div class="flex justify-between items-center gap-1" slot="reference">
        <img class="w-10 h-10 rounded-full" :src="userInfo.avatar" />
        <span class="font-bold text-black">{{ userInfo.name }}</span>
      </div>
    </el-popover>
  </header>
</template>

<style scoped>
header {
  position: sticky;
  top: 0;
  z-index: 9;
  line-height: 1.5;
  /** x y r color**/
  /* box-shadow: 0px 1px 1px #eee; */
  border-bottom: 1px solid #eee;
  backdrop-filter: blur(2px);
}

.logo {
  display: block;
}

nav {
  width: 100%;
  font-size: 12px;
  font-weight: bold;
}

nav a.router-link-exact-active {
  color: var(--color-text);
}

nav a.router-link-exact-active:hover {
  background-color: transparent;
}

nav a {
  display: inline-block;
  padding: 0 1rem;
  border-left: 1px solid var(--color-border);
}

nav a:first-of-type {
  border: 0;
}

@media (min-width: 1024px) {
  header {
    position: sticky;
    top: 0;
    z-index: 9;
    display: flex;
    place-items: center;
    padding-right: calc(var(--section-gap) / 2);
    backdrop-filter: blur(2px);
    border-bottom: 1px solid #eee;
  }

  .logo {
    margin: 0 2rem 0 0;
  }

  nav {
    text-align: left;
    margin-left: -1rem;
    font-size: 1rem;
    padding: 1rem 0;
  }
}
</style>
